package com.yl.module.property.domain;


import java.time.LocalDateTime;

import com.baomidou.mybatisplus.annotation.TableField;
import com.yl.common.constant.Constants;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Objects;

import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.IdType;
import lombok.Getter;
import lombok.experimental.Accessors;
import org.springframework.format.annotation.DateTimeFormat;
import com.fasterxml.jackson.annotation.JsonFormat;

/**
 * 资产表 实体
 * @author makejava
 * @date 2024-10-23 15:54:15
 */
@Data
@Accessors(chain = true)
@TableName("property")
@ApiModel(value = "Property", description = "资产表")
public class Property extends Model<Property> implements Serializable {
	private static final long serialVersionUID = -75800838888437450L;

    @ApiModelProperty(value = "资产表-主键id")
	@TableId(value = "id", type = IdType.AUTO)
    private Integer id;

	@ApiModelProperty(value = "资产编码 例如SN编码这种")
	@TableField("`property_code`")
	private String propertyCode;

	@ApiModelProperty(value = "三方资产唯一标识 例如华为的设备唯一标识")
	@TableField("`tripartite_property_id`")
    private String tripartitePropertyId;

	@ApiModelProperty(value = "资产一级分类id 来源property_type.id")
	@TableField("`property_type_id`")
    private Integer propertyTypeId;

	@ApiModelProperty(value = "资产二级分类id 来源property_type.id")
	@TableField("`property_type_id2`")
	private Integer propertyTypeId2;

	@ApiModelProperty(value = "资产三级分类id 来源property_type.id")
	@TableField("`property_type_id3`")
	private Integer propertyTypeId3;

	@ApiModelProperty(value = "归属区域 例如卫生间、客厅、  厨房等")
	@TableField("`belonging_area`")
	private String belongingArea;

	@ApiModelProperty(value = "资产名称")
	@TableField("`name`")
    private String name;

	@ApiModelProperty(value = "资产品牌")
	@TableField("`brand`")
    private String brand;

	@ApiModelProperty(value = "是否在线 0否 1是 默认在线1")
	@TableField("`is_offline`")
    private Integer isOffline;

	@ApiModelProperty(value = "告警状态 0否 1是 默认无告警0")
	@TableField("`alarm_state`")
    private Integer alarmState;

	@ApiModelProperty(value = "是否闲置 0否 1是 默认0")
	@TableField("`is_idle`")
	private Integer isIdle;

	@ApiModelProperty(value = "bim编码")
	@TableField("`bim_code`")
	private String bimCode;

	@ApiModelProperty(value = "ue编码")
	@TableField("`ue_code`")
	private String ueCode;

	@ApiModelProperty(value = "是否是智能设备 0否 1是 默认否0")
	@TableField("`is_smart`")
    private Integer isSmart;

	@ApiModelProperty(value = "安装日期")
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	@TableField("`install_date`")
    private LocalDateTime installDate;

	@ApiModelProperty(value = "是否开启保养提醒 0否 1是 默认0")
	@TableField("`is_maintain`")
    private Integer isMaintain;

	@ApiModelProperty(value = "保养周期(月)")
	@TableField("`maintain_period`")
    private Integer maintainPeriod;

	@ApiModelProperty(value = "下次保养日期")
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	@TableField("`next_time_maintain`")
    private LocalDateTime nextTimeMaintain;

	@ApiModelProperty(value = "是否开启更换提醒 0否 1是 默认0")
	@TableField("`is_change`")
	private Integer isChange;

	@ApiModelProperty(value = "下次更换日期")
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	@TableField("`lately_change_date`")
	private LocalDateTime latelyChangeDate;

	@ApiModelProperty(value = "最近维修日期")
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	@TableField("`lately_upkeep`")
    private LocalDateTime latelyUpkeep;

	@ApiModelProperty(value = "质保期 例如一个月 三年 十年")
	@TableField("`warranty`")
	private String warranty;

	@ApiModelProperty(value = "使用年限")
	@TableField("`durable_years`")
	private String durableYears;

	@ApiModelProperty(value = "图片编号 图片名称 用于数据导入维护使用 项目中没有使用")
	@TableField("`image_num`")
	private String imageNum;

	@ApiModelProperty(value = "此资产在三维模型中是否可以点击")
	@TableField("`is_click_model`")
	private Integer isClickModel;

	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	@TableField("`create_time`")
    private LocalDateTime createTime;

	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	@TableField("`update_time`")
    private LocalDateTime updateTime;

	@TableField("`delete_flag`")
    private Integer deleteFlag;

	/**
	 * 管理端-资产状态
	 */
	@Getter
	public enum PropertyStateEnum{
		STATE1(1,"正常"),
		STATE2(2,"离线"),
		STATE3(3,"闲置");

		@Getter
		private final Integer code;
		private final String name;

		PropertyStateEnum(Integer code ,String name ){
			this.code = code;
			this.name = name;
		}

		/**
		 * 图标状态转换
		 * @param isSmart 是否是智能设备 0否 1是
		 * @param isOffline 是否在线 0否 1是
		 * @param isIdle 是否闲置 0否 1是
		 * @return
		 */
		public static Integer convertState(Integer isSmart,Integer isOffline,Integer isIdle){
			/*
			状态（状态优先级 从左到右越来越低）
				管理端-资产列表
					智能资产
						闲置 离线 正常
					非智能资产
						闲置 正常
			 */
			if(Constants.YES.equals(isIdle)){
				return Property.PropertyStateEnum.STATE3.getCode();
			}

			if(Constants.YES.equals(isSmart)&&Constants.NO.equals(isOffline)){
				return Property.PropertyStateEnum.STATE2.getCode();
			}

			return Property.PropertyStateEnum.STATE1.getCode();
		}
	}

	/**
	 * UE模型-资产状态
	 */
	@Getter
	public enum PropertyUeStateEnum{
		STATE1(1,"正常"),
		STATE2(2,"告警"),
		STATE3(3,"离线");

		@Getter
		private final Integer code;
		private final String name;

		PropertyUeStateEnum(Integer code ,String name ){
			this.code = code;
			this.name = name;
		}

		/**
		 * 状态转换
		 * @param isOffline 是否在线 0否 1是
		 * @param alarmState 告警状态 0否 1是 默认无告警0
		 */
		public static Integer convertState(Integer isOffline,Integer alarmState){
			/*
			状态state
				正常1
				告警2
				离线3
			 */
			if(Constants.NO.equals(isOffline)){
				return Property.PropertyUeStateEnum.STATE3.getCode();
			}

			if(Constants.YES.equals(alarmState)){
				return Property.PropertyUeStateEnum.STATE2.getCode();
			}

			return Property.PropertyUeStateEnum.STATE1.getCode();
		}
	}

	/**
	 * 资产保养状态枚举
	 */
	@Getter
	public enum MaintainStateEnum{
		STATE1(1,"提醒关闭了或不需要提醒 不需要提示"),
		STATE2(2,"即将保养"),
		STATE3(3,"保养超期");

		@Getter
		private final Integer code;
		private final String name;

		MaintainStateEnum(Integer code ,String name ){
			this.code = code;
			this.name = name;
		}

		/**
		 * 状态转换
		 * @param isMaintain 是否开启保养提醒 0否 1是
		 * @param nextTimeMaintain 下次保养日期
		 * @param currentTime 当前时间
		 */
		public static Integer convertState(Integer isMaintain,LocalDateTime nextTimeMaintain,LocalDateTime currentTime){

			//提醒关闭或保养日期为空 返回正常
			if(Constants.NO.equals(isMaintain)||Objects.isNull(nextTimeMaintain)){
				return Property.MaintainStateEnum.STATE1.getCode();
			}

			//保养超期 当前时间大于保养时间
			if(currentTime.isAfter(nextTimeMaintain)){
				return Property.MaintainStateEnum.STATE3.getCode();
			}

			//正常 小于 当前时间小于保养日期的前30天日期
			LocalDateTime thirtyDaysAgo = nextTimeMaintain.minusDays(30);
			if(currentTime.isBefore(thirtyDaysAgo)){
				return Property.MaintainStateEnum.STATE1.getCode();
			}

			//即将保养
			return Property.MaintainStateEnum.STATE2.getCode();
		}
	}

	/**
	 * 资产更换状态枚举
	 */
	@Getter
	public enum ChangeStateEnum{
		STATE1(1,"提醒关闭了或不需要提醒 不需要提示"),
		STATE2(2,"即将保养"),
		STATE3(3,"保养超期");

		@Getter
		private final Integer code;
		private final String name;

		ChangeStateEnum(Integer code ,String name ){
			this.code = code;
			this.name = name;
		}

		/**
		 * 状态转换
		 * @param isChange 是否开启更换提醒 0否 1是
		 * @param latelyChangeDate 下次更换日期
		 * @param currentTime 当前时间
		 */
		public static Integer convertState(Integer isChange,LocalDateTime latelyChangeDate,LocalDateTime currentTime){

			//提醒关闭或更换日期为空 返回正常
			if(Constants.NO.equals(isChange)||Objects.isNull(latelyChangeDate)){
				return Property.MaintainStateEnum.STATE1.getCode();
			}

			//更换超期 当前时间大于保养时间
			if(currentTime.isAfter(latelyChangeDate)){
				return Property.ChangeStateEnum.STATE3.getCode();
			}

			//正常 小于 当前时间小于保养日期的前30天日期
			LocalDateTime thirtyDaysAgo = latelyChangeDate.minusDays(30);
			if(currentTime.isBefore(thirtyDaysAgo)){
				return Property.ChangeStateEnum.STATE1.getCode();
			}

			//更换保养
			return Property.ChangeStateEnum.STATE2.getCode();
		}
	}

	@Getter
	public enum MaintainUpkeepType{

		TYPE_1(1,"保养"),
		TYPE_2(2,"维修"),
		TYPE_3(3,"更换");

		private final Integer code;
		private final String name;

		MaintainUpkeepType(
				Integer code,
				String name
		){
			this.code = code;
			this.name = name;
		}
	}



}

